#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
using namespace std;
int read(){
    int x=0,f=1;
    char c='\0';
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    while(c=='-'){f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int T=0,n,a[200010];
int dfs(int i,int c,int rdx,int bdx){
    if(i>n-1)return c;
    return max(dfs(i+1,c+=(int)(rdx!=-1&&a[rdx]==a[i])*a[i],i,bdx),
               dfs(i+1,c+=(int)(bdx!=-1&&a[bdx]==a[i])*a[i],rdx,i));
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    T=read();
    while(T--){
        n=read();
        f(i,n)a[i]=read();
        printf("%d\n",dfs(0,0,-1,-1));
    }
    return 0;
}
